package com.sdkx.app.activitys;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.sdkx.app.R;
import com.sdkx.app.fragment.DaoHangSetFragment;
import com.sdkx.app.fragment.SecuritySetFragment;
import com.sdkx.app.fragment.SettingFragment;

public class SettingActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 这句代码修复点击屏幕顶部不灵敏。
        getWindow().setFlags(1024, 1024);
        setContentView(R.layout.activity_setting);
        Intent intent =getIntent();
        String type = intent.getStringExtra("type");
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        switch (type) {
            case "main":
                getFragmentManager().beginTransaction().replace(R.id.fragment_container,new SettingFragment()).commit();
                if(actionBar!=null){
                    actionBar.setTitle("设置");
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
                break;
            case "security":
                getFragmentManager().beginTransaction().replace(R.id.fragment_container,new SecuritySetFragment()).commit();
                if(actionBar!=null){
                    actionBar.setTitle("飞行安全参数设置");
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
                break;
            case "daohang":
                getFragmentManager().beginTransaction().replace(R.id.fragment_container,new DaoHangSetFragment()).commit();
                if(actionBar!=null){
                    actionBar.setTitle("导航详情设置");
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
                break;
            default:
                break;
        }

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
        }
        return false;
    }
}
